/*
 * Copyright (c) 2010, Oracle. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of Oracle nor the names of its contributors
 *   may be used to endorse or promote products derived from this software without
 *   specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

package searchspads;
//import com.sun.pdfview.PDFViewer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.basic.BasicListUI.ListSelectionHandler;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.icepdf.core.views.DocumentViewController;
import org.icepdf.ri.common.ComponentKeyBinding;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.common.views.DocumentViewControllerImpl;
import searchspads.util.JComboCheckBox;

public class ContactEditor extends javax.swing.JFrame {
    public String stringCurrentLanguage;
    /**
     * Creates new form ContactEditor
     */
    public ContactEditor() {
        initComponents();
        viewPdf();
        
    }
    
    private Properties getProperties(){
        Properties prop = new Properties();
	InputStream input = null;
	try {
                   if(this.stringCurrentLanguage.equals("English")){
                     input = getClass().getClassLoader().getResourceAsStream("resources/language_en.properties");   
                   }
                   else{
                       input = getClass().getClassLoader().getResourceAsStream("resources/language_jp.properties");  
                   }
		// load a properties file
		prop.load(input);
	} catch (IOException ex) {
		ex.printStackTrace();
	}  
        return prop;
    }
        public void addControlsForm(){

        Vector<String> v = getDataCombobox(this.stringCurrentLanguage);
        JComboCheckBox cbCheckbox = new JComboCheckBox(v,this);
        
        cbCheckbox.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK,1 ));
        cbCheckbox.setSize(new Dimension(350,25));
        cbCheckbox.setPreferredSize(new Dimension(350, 25));
        cbCheckbox.setLocation(0,0);
        cbCheckbox.setAutoscrolls(true);

        panelCheckbox.add(cbCheckbox);
        panelCheckbox.validate();
        panelCheckbox.repaint();
        
    }
     public Vector<String> getDataCombobox(String typeLanguage){
      Vector<String> v = new Vector<String>();
      try {
           Connection cnn = BoTuongThich.KetNoi();
            String sql = "SELECT * FROM category";
            ResultSet rs = BoTuongThich.executeQuery(sql);
            //setModel();
            while(rs.next()){
                if(this.stringCurrentLanguage.equals("English"))
                {
                    v.add(rs.getString("content_eng"));
                }
                else {
                    v.add(rs.getString("content_jp"));
                }
               //cbsession.addItem(rs.getString("content_eng"));
                
            }
            BoTuongThich.DongKetNoi();
        } catch (Exception e) {
        }
      return v;
    }
    String strpdf = "";
   public void viewPdf(){
       jtablecontent.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                 strpdf = jtablecontent.getValueAt(jtablecontent.getSelectedRow(), 0).toString().trim();
                 String strpdf1 = strpdf.replace("*", "}");
                 String[] str1 = strpdf1.split("}");
                 strpdf = str1[0];
            }
        });
   
   }
   public void setCurrentLangluage(String stringLanguage){
       if(this.stringCurrentLanguage == null){
          this.stringCurrentLanguage = new String(); 
       }
        
                this.stringCurrentLanguage = stringLanguage;
                Properties prop = getProperties();
                viewselectedpdfbtn.setText(prop.getProperty("viewSelectedPDF"));
                exportbtn.setText(prop.getProperty("export"));
                clearbtn.setText(prop.getProperty("clear"));
                helpbtn.setText(prop.getProperty("help"));
                exitbtn.setText(prop.getProperty("exit"));
                orradiobtn.setText(prop.getProperty("or"));
                andradiobtn.setText(prop.getProperty("and"));
                searchbtn.setText(prop.getProperty("search"));
                searchmorebtn.setText(prop.getProperty("searchmore"));
                sessionlb.setText(prop.getProperty("session"));
                typelb.setText(prop.getProperty("type"));
                paneltop.setBorder(javax.swing.BorderFactory.createTitledBorder(prop.getProperty("settingname")));
            LoadDataToTable();
            addControlsForm();
            if(this.stringCurrentLanguage.equals("English")){
                cbsession.removeAllItems();
                loadDataCombobox();
            }else{
                cbsession.removeAllItems();
                loadDataCombobox1();
            }
            
        
        SortButtonRenderer renderer = new SortButtonRenderer();
        TableColumnModel model = jtablecontent.getColumnModel();
         int n = headerStr.length;
        for (int i=0;i<n;i++) {
          model.getColumn(i).setHeaderRenderer(renderer);
        }
    
         JTableHeader header = jtablecontent.getTableHeader();
         header.addMouseListener(new HeaderListener(header,renderer));
   }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
    
    
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        paneltop = new javax.swing.JPanel();
        jTextSearch = new javax.swing.JTextField();
        sessionlb = new javax.swing.JLabel();
        cbItem = new javax.swing.JComboBox();
        searchbtn = new javax.swing.JButton();
        searchmorebtn = new javax.swing.JButton();
        andradiobtn = new javax.swing.JRadioButton();
        orradiobtn = new javax.swing.JRadioButton();
        PanelDate = new javax.swing.JPanel();
        jToggleButton1 = new javax.swing.JToggleButton();
        jToggleButton2 = new javax.swing.JToggleButton();
        jToggleButton3 = new javax.swing.JToggleButton();
        jToggleButton4 = new javax.swing.JToggleButton();
        cbsession = new javax.swing.JComboBox();
        cbtype = new javax.swing.JComboBox();
        typelb = new javax.swing.JLabel();
        panelCheckbox = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        viewselectedpdfbtn = new javax.swing.JButton();
        exportbtn = new javax.swing.JButton();
        clearbtn = new javax.swing.JButton();
        helpbtn = new javax.swing.JButton();
        exitbtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtablecontent = new javax.swing.JTable();

        setTitle("Search Multi");
        setName("searchmulti"); // NOI18N

        paneltop.setBorder(javax.swing.BorderFactory.createTitledBorder("Setting Name"));

        jTextSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextSearchActionPerformed(evt);
            }
        });
        jTextSearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextSearchKeyPressed(evt);
            }
        });

        sessionlb.setText("Session:");

        cbItem.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Any Item", "Title", "Author", "KeyWork", "Chairperson", " " }));
        cbItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbItemActionPerformed(evt);
            }
        });

        searchbtn.setText("Search");

        searchmorebtn.setText("Search more");

        buttonGroup3.add(andradiobtn);
        andradiobtn.setText("AND");

        buttonGroup3.add(orradiobtn);
        orradiobtn.setText("OR");

        PanelDate.setAlignmentX(0.0F);
        PanelDate.setAlignmentY(0.0F);

        jToggleButton1.setSelected(true);
        jToggleButton1.setText("3/25 sun");
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });

        jToggleButton2.setSelected(true);
        jToggleButton2.setText("3/26 mon");

        jToggleButton3.setSelected(true);
        jToggleButton3.setText("3/27 thu");

        jToggleButton4.setSelected(true);
        jToggleButton4.setText("3/29 web");

        org.jdesktop.layout.GroupLayout PanelDateLayout = new org.jdesktop.layout.GroupLayout(PanelDate);
        PanelDate.setLayout(PanelDateLayout);
        PanelDateLayout.setHorizontalGroup(
            PanelDateLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelDateLayout.createSequentialGroup()
                .add(2, 2, 2)
                .add(jToggleButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jToggleButton2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jToggleButton3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jToggleButton4)
                .addContainerGap(142, Short.MAX_VALUE))
        );
        PanelDateLayout.setVerticalGroup(
            PanelDateLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelDateLayout.createSequentialGroup()
                .add(PanelDateLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jToggleButton1)
                    .add(jToggleButton2)
                    .add(jToggleButton3)
                    .add(jToggleButton4))
                .add(0, 0, Short.MAX_VALUE))
        );

        cbsession.setPreferredSize(new java.awt.Dimension(71, 20));
        cbsession.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbsessionActionPerformed(evt);
            }
        });

        cbtype.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Any Type" }));

        typelb.setText("Type:");

        org.jdesktop.layout.GroupLayout panelCheckboxLayout = new org.jdesktop.layout.GroupLayout(panelCheckbox);
        panelCheckbox.setLayout(panelCheckboxLayout);
        panelCheckboxLayout.setHorizontalGroup(
            panelCheckboxLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 349, Short.MAX_VALUE)
        );
        panelCheckboxLayout.setVerticalGroup(
            panelCheckboxLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 35, Short.MAX_VALUE)
        );

        jLabel1.setText("Session");

        org.jdesktop.layout.GroupLayout paneltopLayout = new org.jdesktop.layout.GroupLayout(paneltop);
        paneltop.setLayout(paneltopLayout);
        paneltopLayout.setHorizontalGroup(
            paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, paneltopLayout.createSequentialGroup()
                .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(paneltopLayout.createSequentialGroup()
                        .add(PanelDate, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(153, 153, 153))
                    .add(paneltopLayout.createSequentialGroup()
                        .add(jTextSearch, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 372, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(paneltopLayout.createSequentialGroup()
                        .add(cbItem, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(andradiobtn)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(orradiobtn)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(searchbtn)
                        .add(18, 18, 18)
                        .add(searchmorebtn))
                    .add(paneltopLayout.createSequentialGroup()
                        .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(paneltopLayout.createSequentialGroup()
                                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED))
                            .add(paneltopLayout.createSequentialGroup()
                                .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(typelb, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 41, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(sessionlb, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(26, 26, 26)))
                        .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(cbtype, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(cbsession, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(panelCheckbox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        paneltopLayout.setVerticalGroup(
            paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(paneltopLayout.createSequentialGroup()
                .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextSearch, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(cbItem, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(searchbtn)
                    .add(searchmorebtn)
                    .add(andradiobtn)
                    .add(orradiobtn))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(sessionlb)
                        .add(cbsession, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(PanelDate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(22, 22, 22)
                .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cbtype, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(typelb))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(paneltopLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(paneltopLayout.createSequentialGroup()
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .add(panelCheckbox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        viewselectedpdfbtn.setText("View selected PDF (0)");
        viewselectedpdfbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewselectedpdfbtnActionPerformed(evt);
            }
        });

        exportbtn.setText("Export");
        exportbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportbtnActionPerformed(evt);
            }
        });

        clearbtn.setText("Clear");
        clearbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearbtnActionPerformed(evt);
            }
        });

        helpbtn.setText("Help");

        exitbtn.setText("Exit");

        jScrollPane1.setMinimumSize(new java.awt.Dimension(200, 200));

        jtablecontent.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jtablecontent.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jtablecontent.setToolTipText("");
        jtablecontent.setMaximumSize(new java.awt.Dimension(2147483647, 300));
        jtablecontent.setMinimumSize(new java.awt.Dimension(400, 64));
        jtablecontent.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        jScrollPane1.setViewportView(jtablecontent);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(paneltop, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .add(39, 39, 39)
                .add(viewselectedpdfbtn)
                .add(18, 18, 18)
                .add(exportbtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
                .add(18, 18, 18)
                .add(clearbtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 172, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(helpbtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 149, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(exitbtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 161, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(59, 59, 59))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1084, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(paneltop, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(viewselectedpdfbtn)
                    .add(exportbtn)
                    .add(clearbtn)
                    .add(helpbtn)
                    .add(exitbtn))
                .add(18, 18, 18)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
                .addContainerGap())
        );

        paneltop.getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextSearchActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jTextSearchActionPerformed

private void clearbtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearbtnActionPerformed
    jtablecontent.removeAll();
}//GEN-LAST:event_clearbtnActionPerformed

private void jTextSearchKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextSearchKeyPressed
    String strName = jTextSearch.getText();
    searchDataWhichName(strName);
}//GEN-LAST:event_jTextSearchKeyPressed

private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jToggleButton1ActionPerformed
String strItem;
private void cbItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbItemActionPerformed
    strItem = cbItem.getName().toString().trim();
}//GEN-LAST:event_cbItemActionPerformed

private void cbsessionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbsessionActionPerformed
    
    String str = (String)cbsession.getSelectedItem().toString().toLowerCase();
    if(this.stringCurrentLanguage.equals("English")){
         cbtype.removeAllItems();
         loadDataComboboxwhichString(str);
    }else{
        cbtype.removeAllItems();
        loadDataComboboxwhichString1(str);
    }
   
   
}//GEN-LAST:event_cbsessionActionPerformed
 private void execute() throws Exception{
 
      //  PDFViewer pdfv = new PDFViewer(true);
//        URL url = getClass().getResource("/templates/some.xml");
//        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
    /*    File file = new File(strpdf+".pdf");
        pdfv.openFile(file);
        pdfv.setEnabling();
        pdfv.pack();
        pdfv.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        pdfv.setVisible(true);
        
        */
        
       
 
    }
private void viewselectedpdfbtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewselectedpdfbtnActionPerformed
        
    
        File file = new File("data/"+strpdf+".pdf");
        if(file.exists()){
            
//         if(Desktop.isDesktopSupported()){
//             try {
//                  Desktop.getDesktop().open(file);
//             } catch (Exception e) {
//             }
//         }else{
//         
//         }
            SwingController controller = new SwingController();
         controller.openFileInSomeViewer("data/"+strpdf+".pdf");
         SwingViewBuilder factory = new SwingViewBuilder(controller);
    
         controller.setIsEmbeddedComponent(true);
         // set the viewController embeddable flag.
         DocumentViewController viewController =
                 controller.getDocumentViewController();
 
         JPanel viewerComponentPanel = factory.buildViewerPanel();
         
         // add copy keyboard command
         ComponentKeyBinding.install(controller, viewerComponentPanel);
 
         // add interactive mouse link annotation support via callback
         controller.getDocumentViewController().setAnnotationCallback(
                 new org.icepdf.ri.common.MyAnnotationCallback(
                         controller.getDocumentViewController()));
         
         // build a containing JFrame for display
         JFrame applicationFrame = new JFrame();
         
         applicationFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
 
         applicationFrame.getContentPane().setLayout(new BorderLayout());
         applicationFrame.getContentPane().add(viewerComponentPanel, BorderLayout.CENTER);
         applicationFrame.getContentPane().add(factory.buildCompleteMenuBar(), BorderLayout.NORTH);
         
         // Now that the GUI is all in place, we can try opening a PDF
 
         // hard set the page view to single page which effectively give a single
         // page view. This should be done after openDocument as it has code that
         // can change the view mode if specified by the file.
         controller.setPageViewMode(
                 DocumentViewControllerImpl.ONE_PAGE_VIEW,
                 false);
 
         // show the component
         applicationFrame.pack();
         applicationFrame.setVisible(true);
            
        
        }    
         
}//GEN-LAST:event_viewselectedpdfbtnActionPerformed
public void toExcel(JTable table, File file){
    try{

        FileWriter excel = new FileWriter(file);

        for(int i = 0; i < model.getColumnCount(); i++){
            excel.write(model.getColumnName(i) + "\t");
        }

        excel.write("\n");

        for(int i=0; i< model.getRowCount(); i++) {
            for(int j=0; j < model.getColumnCount(); j++) {
                excel.write(model.getValueAt(i,j).toString()+"\t");
            }
            excel.write("\n");
        }

        excel.close();

    }catch(IOException e){ System.out.println(e); }
}

public void exportTable(JTable table, File fileName){
     DefaultTableModel dtm = (DefaultTableModel) table.getModel();
     try {
         Workbook wb = new HSSFWorkbook();
    CreationHelper createhelper = wb.getCreationHelper();
    Sheet sheet = wb.createSheet("new sheet");
    Row row = null;
    Cell cell = null;
    StringBuffer bufferHeader = new StringBuffer();
     int nCol = dtm.getColumnCount();
    for (int j = 0; j < nCol; j++) {
        bufferHeader.append(dtm.getColumnName(j));
        if (j!=nCol) bufferHeader.append(", ");
    }
//    wb.write(bufferHeader.toString() + "\r\n");
     //write the header information
          

            
    for (int i=0;i<dtm.getRowCount();i++) {
        row = sheet.createRow(i);
        for (int j=0;j<dtm.getColumnCount();j++) {
            cell = row.createCell(j);
            cell.setCellValue((String) dtm.getValueAt(i, j));
        }
    }
     
    
    FileOutputStream out = new FileOutputStream(fileName);
    wb.write(out);
    out.close();
     } catch (Exception e) {
     }
    
    }
 
private void exportbtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportbtnActionPerformed
    JFileChooser fc = new JFileChooser();
     int option = fc.showSaveDialog(ContactEditor.this);
     if(option == JFileChooser.APPROVE_OPTION){
        String filename = fc.getSelectedFile().getName(); 
        String path = fc.getSelectedFile().getParentFile().getPath();

            int len = filename.length();
            String ext = "";
            String file = "";

            if(len > 4){
                    ext = filename.substring(len-4, len);
            }

            if(ext.equals(".xls")){
                    file = path + "\\" + filename; 
            }else{
                    file = path + "\\" + filename + ".xls"; 
            }
            exportTable(jtablecontent, new File(file));
        }

}//GEN-LAST:event_exportbtnActionPerformed
     public void LoadDataToTable()
    {
        try {
           Connection cnn = BoTuongThich.KetNoi();
            String sql = "SELECT * FROM session";
            ResultSet rs = BoTuongThich.executeQuery(sql);
            setModel();
            while(rs.next()){
                Vector v = new Vector();
                String sessionid = rs.getString("sessionID");
                String category = rs.getString("category");
                String AbstNo = sessionid + "*" +category;
                v.add(AbstNo);
                String date = rs.getString("schedules");
                date = date.replaceAll("月", "/");
                String time = rs.getString("time");
                String[] dateslip = date.split("日");
                String datetime = dateslip[0] +"  "+ time;
                v.add(datetime);
                v.add(rs.getString("title"));
                v.add(rs.getString("speaker"));
                v.add(rs.getString("affiliation"));    
                v.add(rs.getString("chair"));
                model.addRow(v);        
            }
            jtablecontent.setModel(model);
            jtablecontent.setShowVerticalLines(true);
            jtablecontent.setShowHorizontalLines(true);
            
            BoTuongThich.DongKetNoi();
        } catch (Exception e) {
        }
    }
     
     
     
     public void loadDataCombobox(){
         try {
           Connection cnn = BoTuongThich.KetNoi();
            String sql = "SELECT * FROM category";
            ResultSet rs = BoTuongThich.executeQuery(sql);
            setModel();
            while(rs.next()){
               cbsession.addItem(rs.getString("content_eng"));
            }
            BoTuongThich.DongKetNoi();
        } catch (Exception e) {
        }
     }
     
     public void loadDataCombobox1(){
         try {
           Connection cnn = BoTuongThich.KetNoi();
            String sql = "SELECT * FROM category";
            ResultSet rs = BoTuongThich.executeQuery(sql);
            setModel();
            while(rs.next()){
               cbsession.addItem(rs.getString("content_jp"));
            }
            BoTuongThich.DongKetNoi();
        } catch (Exception e) {
        }
     }
     public void loadDataComboboxwhichString(String strName){
         try {
            Connection cnn = BoTuongThich.KetNoi();
            String sql = "";
            ResultSet rs;
            sql = "SELECT title_eng FROM category where content_eng = '"+ strName +"' group by title_eng";
            rs = BoTuongThich.executeQuery(sql); 
            setModel();
            while(rs.next()){
                cbtype.addItem(rs.getString("title_eng"));
            }
            
            BoTuongThich.DongKetNoi();
        } catch (Exception e) {
        }
     }
     
     public void loadDataComboboxwhichString1(String strName){
         try {
            Connection cnn = BoTuongThich.KetNoi();
            String sql = "";
            ResultSet rs;
            rs = BoTuongThich.executeQuery(sql);
             sql = "SELECT title_jp FROM category where content_jp = '"+ strName +"' group by title_jp";
            
             
             
            setModel();
            while(rs.next()){
                cbtype.addItem(rs.getString("title_jp"));
            }
            
            BoTuongThich.DongKetNoi();
        } catch (Exception e) {
        }
     }
 String[] headerStr = {"Abst. No.","Time & Date","Title","Author","Institution", "Chairperson" };  
   SortableTableModel model;
    private void setModel(){
        model = new SortableTableModel();
        Properties prop = getProperties();
        model.addColumn(prop.getProperty("abst"));
        model.addColumn(prop.getProperty("timedate"));
        model.addColumn(prop.getProperty("title"));
        model.addColumn(prop.getProperty("author"));
        model.addColumn(prop.getProperty("institution"));
        model.addColumn(prop.getProperty("chairperson"));
    }

 
    private void searchDataWhichName(String strName){
        try {
           Connection cnn = BoTuongThich.KetNoi();
            String sql = "SELECT * FROM session WHERE title LIKE'%"+ strName +"%'";
            ResultSet rs = BoTuongThich.executeQuery(sql);
            setModel();
            while(rs.next()){
                Vector v = new Vector();
                String sessionid = rs.getString("sessionID");
                String category = rs.getString("category");
                String AbstNo = sessionid + "*" +category;
                v.add(AbstNo);
                String date = rs.getString("schedules");
                date = date.replaceAll("月", "/");
                String time = rs.getString("time");
                String[] dateslip = date.split("日");
                String datetime = dateslip[0] +"  "+ time;
                v.add(datetime);
                v.add(rs.getString("title"));
                v.add(rs.getString("speaker"));
                v.add(rs.getString("affiliation"));    
                v.add(rs.getString("chair"));
                model.addRow(v);  
            }
            jtablecontent.setModel(model);
            jtablecontent.setShowVerticalLines(true);
            jtablecontent.setShowHorizontalLines(true);
            
            BoTuongThich.DongKetNoi();
        } catch (Exception e) {
        }
    }
//     public Class getColumnClass(int col) {
//        switch (col) {
//          case  0: return String.class;
//          case  1: return String.class;
//          case  2: return String.class;
//          case  3: return String.class;
//          case  4: return String.class;
//          default: return String.class;
//        }
//      }
    class HeaderListener extends MouseAdapter {
    JTableHeader   header;
    SortButtonRenderer renderer;
   
    HeaderListener(JTableHeader header,SortButtonRenderer renderer) {
      this.header   = header;
      this.renderer = renderer;
    }
   
    public void mousePressed(MouseEvent e) {
      int col = header.columnAtPoint(e.getPoint());
      int sortCol = header.getTable().convertColumnIndexToModel(col);
      renderer.setPressedColumn(col);
      renderer.setSelectedColumn(col);
      header.repaint();
       
      if (header.getTable().isEditing()) {
        header.getTable().getCellEditor().stopCellEditing();
      }
       
      boolean isAscent;
      if (SortButtonRenderer.DOWN == renderer.getState(col)) {
        isAscent = true;
      } else {
        isAscent = false;
      }
      ((SortableTableModel)header.getTable().getModel())
        .sortByColumn(sortCol, isAscent);   
    }
   
    public void mouseReleased(MouseEvent e) {
      int col = header.columnAtPoint(e.getPoint());
      renderer.setPressedColumn(-1);                // clear
      header.repaint();
    }
  }
    /**
     * @param args the command line arguments
     */
    
    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels=javax.swing.UIManager.getInstalledLookAndFeels();
            for (int idx=0; idx<installedLookAndFeels.length; idx++)
                if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {
                    javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
                    break;
                }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ContactEditor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ContactEditor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ContactEditor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ContactEditor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ContactEditor().setVisible(true);  
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PanelDate;
    private javax.swing.JRadioButton andradiobtn;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JComboBox cbItem;
    private javax.swing.JComboBox cbsession;
    public javax.swing.JComboBox cbtype;
    private javax.swing.JButton clearbtn;
    private javax.swing.JButton exitbtn;
    private javax.swing.JButton exportbtn;
    private javax.swing.JButton helpbtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextSearch;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton2;
    private javax.swing.JToggleButton jToggleButton3;
    private javax.swing.JToggleButton jToggleButton4;
    private javax.swing.JTable jtablecontent;
    private javax.swing.JRadioButton orradiobtn;
    private javax.swing.JPanel panelCheckbox;
    private javax.swing.JPanel paneltop;
    private javax.swing.JButton searchbtn;
    private javax.swing.JButton searchmorebtn;
    private javax.swing.JLabel sessionlb;
    private javax.swing.JLabel typelb;
    private javax.swing.JButton viewselectedpdfbtn;
    // End of variables declaration//GEN-END:variables
    
}
